home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Temático 40 Febrero 2004.iso / DOS / testdisk / src / lvm.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-01-09  |  2.8 KB  |  88 lines

  1. /*
  2.  
  3.     File: lvm.c
  4.  
  5.     Copyright (C) 1998-2004 Christophe GRENIER <grenier@cgsecurity.org>
  6.   
  7.     This software is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.   
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.   
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  */
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include "types.h"
  25. #include "common.h"
  26. #include "lvm.h"
  27. #include "intrface.h"
  28. #include "fnctdsk.h"
  29. int check_LVM(t_param_disk *disk_car,t_diskext *partition,const int debug)
  30. {
  31.   unsigned char buffer[8*SECTOR_SIZE];
  32.   if(disk_car->read(disk_car,8, &buffer, partition->lba)!=0)
  33.   { return 1; }
  34.   if(test_LVM(disk_car,(pv_disk_t *)&buffer,partition,debug,0)!=0)
  35.     return 1;
  36.   return 0;
  37. }
  38.  
  39. int recover_LVM(t_param_disk *disk_car, const pv_disk_t *pv,t_diskext *partition,const int debug, const int dump_ind)
  40. {
  41.   if(test_LVM(disk_car,pv,partition,debug,dump_ind)!=0)
  42.     return 1;
  43.   partition->part_type=(unsigned char)P_LVM;
  44.   partition->part_size=(dword)pv->pv_size;
  45.   if(debug!=0)
  46.   {
  47.     ecrit_rapport("part_size %lu\n",partition->part_size);
  48.   }
  49.   return 0;
  50. }
  51.  
  52. int test_LVM(t_param_disk *disk_car, const pv_disk_t *pv,t_diskext *partition,const int debug, const int dump_ind)
  53. {
  54.   if ((strncmp((const char *)pv->id,LVM_ID,sizeof(pv->id)) == 0) && ((pv->version == 1) || (pv->version == 2)))
  55.   {
  56.     uint32_t size;
  57.     if(dump_ind!=0)
  58.     {
  59.       ecrit_rapport("\nLVM magic value at %u/%u/%u\n", LBA2cylinder(disk_car,partition->lba),LBA2head(disk_car,partition->lba),LBA2sector(disk_car,partition->lba));
  60.       /* There is a little offset ... */
  61. /*     dump(stdscr,pv,SECTOR_SIZE); */
  62.     }
  63.     if (pv->pv_size > LVM_MAX_SIZE)
  64.       return (1);
  65.     if ((pv->pv_status != 0) && (pv->pv_status != PV_ACTIVE))
  66.       return (1);
  67.     if ((pv->pv_allocatable != 0) && (pv->pv_allocatable != PV_ALLOCATABLE))
  68.       return (1);
  69.     if (pv->lv_cur > MAX_LV)
  70.       return (1);
  71.     if (strlen((const char *)pv->vg_name) > NAME_LEN / 2)
  72.       return (1);
  73.     size = pv->pe_size / LVM_MIN_PE_SIZE * LVM_MIN_PE_SIZE;
  74.     if ((pv->pe_size != size) ||
  75.     (pv->pe_size < LVM_MIN_PE_SIZE) ||
  76.     (pv->pe_size > LVM_MAX_PE_SIZE))
  77.       return (1);
  78.  
  79.     if (pv->pe_total > ( pv->pe_on_disk.size / sizeof ( disk_pe_t)))
  80.       return (1);
  81.     if (pv->pe_allocated > pv->pe_total)
  82.       return (1);
  83.     partition->upart_type=UP_LVM;
  84.     return 0;
  85.   }
  86.   return 1;
  87. }
  88.